var taskScore = {
    id: "taskScoreTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

taskScore.initColumn = function () {// 初始化表格的列
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '任务', field: 'typeName', align: 'center', valign: 'middle', sortable: true},
        {title: '获得积分', field: 'points', align: 'center', valign: 'middle', sortable: true}
    ];
};

taskScore.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        taskScore.seItem = selected[0];
        return true;
    }
};

taskScore.addtaskScore = function () {//点击添加
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['60%', '70%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/taskScore/taskScore_add'
    });
    this.layerIndex = index;
};

taskScore.updatetaskScore = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改',
            area: ['60%', '70%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/taskScore/taskScore_update/' + taskScore.seItem.id
        });
        this.layerIndex = index;
    }
};

taskScore.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/taskScore/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            window.taskScore.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};

taskScore.formParams = function () {//查询表单提交参数对象 @returns {{}}
    var queryData = {};
    queryData['typeName'] = $("#typeName").val();
    return queryData;
};

taskScore.resetSearch = function () {
    $("#typeName").val("");
    taskScore.search();
};

taskScore.search = function () {//查询列表
    taskScore.table.refresh({query: taskScore.formParams()});
};

$(function () {
    var defaultColunms = taskScore.initColumn();
    var table = new BSTable(taskScore.id, "/taskScore/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(taskScore.formParams());
    taskScore.table = table.init();
    taskScore.table = table;
});